﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Inner.Master"
    CodeBehind="Calendar.aspx.vb" Inherits="LecturerAppointmentSystem.Calendar" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
    <link href="Style.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <table align="right" class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <br />
    <table class="style1">
        <tr>    
            <td valign="top" style="width:10%">

                <asp:Button ID="btn_MonthView" runat="server" Text="Switch to month view" />
                <br />
            </td>
            <td valign="top" style="width:30%">

            <asp:UpdatePanel ID="lblSelectedDateUpdatePanel" runat="server">
    <ContentTemplate>
    
    <asp:Calendar ID="AppointmentCalendar" runat="server" BackColor="White" BorderColor="White"
        BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px"
        NextPrevFormat="FullMonth" Width="350px" SelectedDate='<%# DateTime.Now %>' >
        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
        <OtherMonthDayStyle ForeColor="#999999" />
        <SelectedDayStyle BackColor="Aqua" ForeColor="White" />
        <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True"
            Font-Size="12pt" ForeColor="#333399" />
        <TodayDayStyle BackColor="Turquoise"/>
        <WeekendDayStyle ForeColor="DarkGray" BackColor="LightGray"/>
    </asp:Calendar>
    <br />
    <asp:Label ID="lbl_selectedDate" runat="server" Text="Label"></asp:Label>
    </ContentTemplate>
    </asp:UpdatePanel>
                &nbsp;</td>
            <td style="width:50%;">
            <asp:MultiView ID="CalendarMultiView" runat="server">
    <asp:View ID="LecturerView" runat="server">
    <asp:GridView ID="LecturerGridView" runat="server" DataKeyNames="TimeSlot" AutoGenerateColumns="False"
        DataSourceID="LecturerCalendarDataSource" EnableModelValidation="True" AllowSorting="True">
        <Columns>
            <asp:TemplateField ShowHeader="True">
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" OnClick="ImgBtn_Click"
                        ImageUrl="~/Images/Edit.jpg" Width="25" Height="25"/>
                        <br />
                    <asp:LinkButton ID="lb_appointmentStatus" runat="server" Text='<%# changeText(Eval("Place"))%>' OnClick="LinkButton_Click"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
            <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
            <asp:BoundField DataField="Agenda" HeaderText="Agenda" SortExpression="Agenda" />
            <%--<asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="changeStatus"
                        Text='<%# changeButtonText(Eval("TimeSlot")) %>' CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" />
                        <asp:Button ID="Button2" runat="server" Visible="false" />                    
                </ItemTemplate>
            </asp:TemplateField>--%>
            <asp:TemplateField HeaderText="Booked By">
                <ItemTemplate>
                    <asp:Label ID="lbl_BookedBy" runat="server" Text='<%# parseBooked(Eval("Booked")) %>'></asp:Label>
                    <br />
                    <asp:LinkButton ID="linkButton_BookedBy" runat="server" Text=""></asp:LinkButton>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Booked") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:Label ID="lblresult" runat="server" />
        <br />
        <asp:GridView ID="GridView1" runat="server" 
            DataSourceID="LecturerCalendarDataSource" EnableModelValidation="True">
        </asp:GridView>
    <br />
    <asp:Button ID="btnShowAvailablePopup" runat="server" Style="display: none" />
    <br />
    <asp:ModalPopupExtender ID="AvailablePopup" runat="server" TargetControlID="btnShowAvailablePopup"
        PopupControlID="placePanel" CancelControlID="ButtonCancel"></asp:ModalPopupExtender>
    <asp:Panel ID="placePanel" runat="server" CssClass="modalPopupPanel">
        <asp:Label ID="lbl_TimeSlot" runat="server" Visible="false"></asp:Label>
        <asp:Label ID="placeLabel" runat="server" Text="Please enter the location for the appointment"></asp:Label>
        <asp:TextBox ID="tb_Place" runat="server"></asp:TextBox>
        <br />
        <br />
        <div style="text-align: right;">
            <asp:Button ID="ButtonSave" runat="server" Text="Save" CommandName="Save" OnClick="ButtonSave_Click" />
            <asp:Button ID="ButtonCancel" runat="server" Text="Cancel" />
        </div>
    </asp:Panel>
    <br />
    <asp:Button ID="btnShowUnavailablePopup" runat="server" Style="display: none" />
    <asp:ModalPopupExtender ID="UnavailablePopup" runat="server" TargetControlID="btnShowUnavailablePopup" PopupControlID="UnavailablePanel" CancelControlID="ButtonNo"></asp:ModalPopupExtender>
    <asp:Panel ID="UnavailablePanel" runat="server" CssClass="modalPopupPanel">
        <asp:Label ID="lbl_Unavailable" runat="server" Text="Are you sure you want to mark this slot as unavailable for an appointment?"></asp:Label>
        <br />
        <asp:Button ID="ButtonYes" runat="server" Text="Yes" CommandName="YesMarkAsUnavailable"
            OnClick="ButtonYes_Click" />
        <asp:Button ID="ButtonNo" runat="server" Text="No" />
    </asp:Panel>
    <br />
    <asp:Button ID="btnShowCancelBookedAppointmentPopup" runat="server" Style="display: none" />
    <br />
    <asp:ModalPopupExtender ID="CancelBookingPopup" runat="server" TargetControlID="btnShowCancelBookedAppointmentPopup"
        PopupControlID="CancelBookingPanel" CancelControlID="ButtonDoNotCancel"></asp:ModalPopupExtender>
    <asp:Panel ID="CancelBookingPanel" runat="server" CssClass="modalPopupPanel">
        <asp:Label ID="lbl_CancelBooking" runat="server" Text="Current slot already contains a booking. Please cancel the booking first."></asp:Label>
        <br />
        <br />
        <div style="text-align: right;">
            <asp:Button ID="ButtonOkCancel" runat="server" Text="Cancel Appointment" CommandName="CancelAppointment" OnClick="ButtonOkCancel_Click" />
            <asp:Button ID="ButtonDoNotCancel" runat="server" Text="Cancel" />
        </div>
    </asp:Panel>
    <asp:SqlDataSource ID="LecturerCalendarDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
        ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
        SelectCommand="SELECT TimeSlots.ID, TimeSlots.TimeSlot, derivedtbl_1.ID AS Expr1, derivedtbl_1.AppointmentDate, derivedtbl_1.Fkid_TimeSlot, derivedtbl_1.Place, derivedtbl_1.Agenda, derivedtbl_1.Booked, derivedtbl_1.Lecturer FROM (TimeSlots LEFT OUTER JOIN (SELECT ID, AppointmentDate, Fkid_TimeSlot, Place, Agenda, Booked, Lecturer FROM Appointments WHERE (AppointmentDate = ?) AND (Lecturer = ?)) derivedtbl_1 ON derivedtbl_1.Fkid_TimeSlot = TimeSlots.ID)">
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="" Name="?" QueryStringField="Date" />
            <asp:QueryStringParameter DefaultValue="" Name="?" QueryStringField="UserId" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <br />
    <%--<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"
        EnableModelValidation="True" AllowSorting="True">
        <Columns>
            <asp:BoundField DataField="TimeSlot" HeaderText="TimeSlot" SortExpression="TimeSlot" />
            <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
            <asp:BoundField DataField="Agenda" HeaderText="Agenda" SortExpression="Agenda" />
            <asp:TemplateField HeaderText="Booked" SortExpression="Booked">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Booked") %>' />
                </EditItemTemplate>
                <ItemTemplate>
                    <%# Eval("Booked")%>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
        ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
        SelectCommand="SELECT TimeSlots.ID, TimeSlots.TimeSlot, derivedtbl_1.ID AS Expr1, derivedtbl_1.AppointmentDate, derivedtbl_1.Fkid_TimeSlot, derivedtbl_1.Place, derivedtbl_1.Agenda, derivedtbl_1.Booked, derivedtbl_1.Lecturer FROM (TimeSlots LEFT OUTER JOIN (SELECT ID, AppointmentDate, Fkid_TimeSlot, Place, Agenda, Booked, Lecturer FROM Appointments WHERE (AppointmentDate = ?) AND (Lecturer = ?)) derivedtbl_1 ON derivedtbl_1.Fkid_TimeSlot = TimeSlots.ID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="?" QueryStringField="Date" />
            <asp:QueryStringParameter Name="?" QueryStringField="UserId" />
        </SelectParameters>
    </asp:SqlDataSource>--%>
    <br />
    </asp:View>
    <asp:View ID="StudentView" runat="server">
    
        <asp:GridView ID="StudentGridView" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataSourceID="StudentCalendarDataSource" 
            EnableModelValidation="True">
            <Columns>
                <asp:BoundField DataField="TimeSlot" HeaderText="TimeSlot" 
                    SortExpression="TimeSlot" />
                <asp:TemplateField HeaderText="Appointments" SortExpression="Booked">
                    <ItemTemplate>
                        <asp:Label ID="lbl_Appointment" runat="server" Text='<%# getStatus(Eval("Booked")) %>'></asp:Label>
                        <br />
                        <asp:LinkButton ID="lb_ShowDetails" runat="server" Text="Click for details" Visible='<%# getVisibility(Eval("Booked")) %>'></asp:LinkButton> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
        <asp:SqlDataSource ID="StudentCalendarDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>" 
            SelectCommand="SELECT TimeSlots.ID, TimeSlots.TimeSlot, derivedtbl_1.ID AS Expr1, derivedtbl_1.AppointmentDate, derivedtbl_1.Fkid_TimeSlot, derivedtbl_1.Place, derivedtbl_1.Agenda, derivedtbl_1.Booked, derivedtbl_1.Lecturer FROM (TimeSlots LEFT OUTER JOIN (SELECT ID, AppointmentDate, Fkid_TimeSlot, Place, Agenda, Booked, Lecturer, BookedBy FROM BookedSlotsQuery WHERE (AppointmentDate = ?) AND (BookedBy = ?)) derivedtbl_1 ON derivedtbl_1.Fkid_TimeSlot = TimeSlots.ID)">
            <SelectParameters>
                <asp:QueryStringParameter Name="AppointmentDate" QueryStringField="Date" 
                    Type="String" />
                <asp:QueryStringParameter Name="BookedBy" QueryStringField="UserId" 
                    Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:View>
    </asp:MultiView>
                &nbsp;</td>
        </tr>
    </table>
    
    <br />
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <asp:ConfirmButtonExtender ID="Button1_ConfirmButtonExtender" runat="server" ConfirmText="Click OK to make the Label say OK or click Cancel to
	Cancel the Operation" Enabled="True" TargetControlID="Button1">
            </asp:ConfirmButtonExtender>
        </ContentTemplate>
    </asp:UpdatePanel><br />
    <br />
    <br />
    <br />
    
</asp:Content>
